import axios from '@/utils/http';
import base from './base';

// 发送验证码
export const sendCode = phone => axios.post(
  `${base.sq}/phone_verify_codes`,
  { phone },
);

// 获取网站统计信息
export const loadWebsiteStatistics = () => axios.get(
  `${base.sq}/station_data`,
);

// 获取上传密钥
export const uploadToken = () => axios.get(
  `${base.sq}/qinius`,
);

// 匹配学校
export const companyMatching = params => axios.get(
  `${base.sq}/search`,
  {
    params: {
      select_type: 'School',
      title: params.title,
    },
  },
);

// 上传到七牛
export const upload = formData => axios.post(
  'https://up-z2.qiniup.com',
  formData,
  {
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
  },
);

// 检查积分
export const score = params => axios.get(
  `${base.sq}/exp`,
  {
    params: {
      key: params.type,
    },
  },
);

// 获取积分规则
export const scoreRules = () => axios.get(
  `${base.sq}/station_data/score_action`,
);

// 点赞、收藏等操作
export const vote = params => axios.post(
  `${base.sq}/votes`,
  {
    votable_type: params.votePosition, // 点赞发生的位置
    votable_id: params.votePositionId, // 点赞发生位置的id
    vote_scope: params.voteAction, // 收藏、点赞，操作类型
    is_vote: params.voteState, // true or false 投票还是取消投票
  },
);

// 下载
export const download = params => axios.get(
  `${base.sq}/downloads`,
  {
    params: {
      key: params.key,
      product_file_id: params.docId,
      current_file_id: params.curFileId,
    },
  },
);

// 收藏
export const collectionList = params => axios.get(
  `${base.sq}/votes`,
  {
    params: {
      user_id: params.userId,
      votable_type: params.type,
      vote_scope: 'collection',
      page: params.page,
    },
  },
);

// 每周空间统计信息
export const popularizeInfos = params => axios.get(
  `${base.sq}/products/collect_data`,
  {
    params: {
      product_ids: params.spaceIds,
    },
  },
);

// 第三方登录
export const otherSignIn = params => axios.post(
  `${base.sq}/oauth_login`,
  {
    open_id: params.openId,
    type: params.type,
  },
);

// 获取yozo的preview网址
export const getYozoPreview = params => axios.get(
  'https://api.yozocloud.cn/getPreview',
  {
    params: {
      k: '52271564374566502430207',
      url: params.url,
    },
  },
);

// 该页面的小程序二维码
export const wxCodeUrl = params => axios.get(
  `${base.sq}/shares/wechat`,
  {
    params: {
      qr_wechatable_type: params.type, // 'Issue' 'ProductFile' 'Product'
      qr_wechatable_id: params.id,
      info: {
        page: params.page,
        scene: params.scene,
      },
    },
  },
);
